var gridList;
var key;
$(document).ready(function () {
    key = mini.get("key").getValue();
    gridList = mini.get("gridList");
    init_Data();
});

function init_Data() {
    gridList.load({'sysEntrust.entrustConsigner': window.top.UserInfo.userId});
}

function search() {
    var key = mini.get("key").getValue();
    gridList.load({
        'sysEntrust.entrustConsigner': window.top.UserInfo.userId,
        'sysEntrust.key': key
    });
}

function onKeyEnter(e) {
    search();
}

function formatOper(e) {
    var row = e.record;
    return "<a class='mini-button' hideFocus='' href='javascript:void(0)' onClick='editData(\"" + e.value + "\")'><span class='mini-button-text  mini-button-icon icon-edit'>修改</span></a><span class='separator'></span>" +
        "<a class='mini-button' hideFocus='' href='javascript:void(0)' onClick='removeData(\"" + e.value + "\",\"" + row.entrustId + "\")'><span class='mini-button-text  mini-button-icon icon-remove'>删除</span></a>";
}

function addData() {
    /**请修改url路径，从根目录开始 如：web/base/mysysUser/mysysUserEdit.html**/
    mini.open({
        url: "base/sysEntrust/sysEntrustDetail.html?type=new&temp=" + new Date().getUTCMilliseconds(),
        title: "添加委托管理", width: 1000, height: 600,
        onload: function () {
            //给对话框传参数！
            //var iframe = this.getIFrameEl();
            //iframe.contentWindow.SetData("");
        },
        ondestroy: function (e) {
            if (e == "OK") {
                init_Data();
            }
        }
    });
}

function editData(id) {
    /**请修改url路径，从根目录开始 如：web/base/mysysUser/mysysUserEdit.html**/
    mini.open({
        url: "base/sysEntrust/sysEntrustDetail.html?type=edit&id=" + id + "&temp=" + new Date().getUTCMilliseconds(),
        title: "修改委托管理", width: 1000, height: 600,
        onload: function () {
            //给对话框传参数！
            //var iframe = this.getIFrameEl();
            //iframe.contentWindow.SetData("");
        },
        ondestroy: function (e) {
            if (e == "OK") {
                init_Data();
            }
        }
    });
}

function removeData(id, title) {
    mini.confirm("您确定要删除这条委托吗？", "删除确认", function (action) {
        if (action != "ok") {
            return;
        }
        ActHttpRequest("sysEntrust!del.do?id=" + id, {}, function (data) {
            if (data.OK == "OK") {
                init_Data();
            } else {
                mini.alert(data.message);
            }
        }, null, null, null, '删除中。。。', true);
    });
}
